package com.qdu.reducer;
import com.qdu.bean.bikeWritable;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import java.io.IOException;
import java.text.DecimalFormat;


public class TempAvgReducer extends Reducer<bikeWritable, DoubleWritable, Text, Text> {


    @Override
    protected void reduce(bikeWritable key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {
        double sum=0;
        int count=0;
        for (DoubleWritable s :
                values) {
            sum+=s.get();
            count++;
        }
        DecimalFormat df =new DecimalFormat("#0.00");
        context.write(new Text(key.toString()),new Text(df.format(sum/count)));
    }
}
